home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Newformat
- ** a REALLY simple XFNC to see if a stack is hypercard 2.0 format or not.
- ** Just take a look at the 20th byte in the file and see if it is 10.
- ** See, toldya it was simple...
- **
- ** By Neil Day 9/24/90
- ** Electronic Media Group
- ** © 1990 Apple Computer, Inc.
- **
- ** Compile and link with the following MPW commands
- **
- ** c -b newformat.c
- ** link -w -rt XFCN=22503 ∂
- ** -m ENTRYPOINT∂
- ** -sg newformat newformat.c.o∂
- ** "{libraries}HyperXLib.o" ∂
- ** "{libraries}Interface.o" ∂
- ** "{Clibraries}"StdCLib.o ∂
- ** "{Clibraries}"CInterface.o ∂
- ** "{Clibraries}"CRuntime.o ∂
- ** -o "vessel"
- **
- */
-
- #include <types.h> /* Compiler Interfaces to */
- #include <resources.h> /* various managers and */
- #include <files.h> /* resources ... */
- #include <Packages.h>
- #include <String.h>
- #include <OSEvents.h>
- #include <Memory.h>
- #include <Events.h>
- #include <Errors.h>
- #include <Desk.h>
- #include <Strings.h>
- #include <Memory.h>
- #include <OSUtils.h>
- #include <HyperXCmd.h>
-
- #define BUFFER_SIZE 512
-
- HParmBlkPtr openFile (char *name,unsigned char prm); /* Function Prototypes */
- Handle str2h (char *str);
- void h2pstr (char *dest,Handle source);
-
- pascal void EntryPoint (XCmdPtr paramPtr)
- {
- HParmBlkPtr ioBlock; /* paramater block for file IO */
- char fileName[256]; /* the name of the file to check*/
- Boolean result = false; /* the result of the function */
- char *bufptr; /* pointer to ioBuffer */
- char errorstr[256];
- OSErr error; /* a place for errors */
-
- if (paramPtr->paramCount != 1) { /* Wrong number of params??? */
- paramPtr->returnValue = str2h ("false"); /* return false... */
- return; /* leave the function */
- }
-
- h2pstr (fileName,paramPtr->params[0]); /* copy and Pascalize filename */
-
- ioBlock = openFile (fileName,fsRdPerm); /* open the file for reading */
-
- if (ioBlock != 0) { /* if we had a happy open */
- ioBlock->ioParam.ioPosMode = fsFromStart; /* read from start of file... */
- ioBlock->ioParam.ioPosOffset = 0; /* let's start at the beginning */
- ioBlock->ioParam.ioReqCount = 22; /* and read 18 bytes or so... */
- error = PBRead ((ParmBlkPtr)ioBlock,false); /* actually read it... */
-
- bufptr = ioBlock->ioParam.ioBuffer; /* copy address of buffer */
-
- if ((*(bufptr+19) == 10) && (!error)) /* byte 16 = 10 ?? No Error??? */
- result = true; /* return true */
-
- DisposPtr (ioBlock->ioParam.ioBuffer); /* free the buffer space */
- DisposPtr ((Ptr)ioBlock); /* free the space for the block */
- PBClose ((ParmBlkPtr)ioBlock,false); /* close that puppy up */
- }
-
- if (result) /* given the value of result */
- paramPtr->returnValue = str2h ("true"); /* return true */
- else
- paramPtr->returnValue = str2h ("false"); /* or false, depending... */
-
- return;
- }
-
- /*
- **
- ** openFile
- ** This little beauty allocates space for a parmBlock and the associated buffer (checking
- ** fer errors, of course). It then proceedes to open the file with the specified privleges
- ** and return error codes, if any....
- */
-
- HParmBlkPtr openFile (name,prm)
- char *name;
- unsigned char prm;
- {
- OSErr err; /* a place to put errors */
- unsigned char *buffer; /* pointer to a new buffer */
- HParmBlkPtr block; /* paramater block to be... */
-
-
- block = (HParmBlkPtr) NewPtrClear (sizeof (HParamBlockRec)); /* Allocate for a ParamBlock */
- if ((block == 0) || MemError()) /* if NewPtr failed, return a */
- return (HParmBlkPtr) 0; /* error that thinks its a ptr */
-
- buffer = NewPtrClear (BUFFER_SIZE); /* Allocate buffer space */
- if ((buffer == 0) || MemError()) /* if NewPtr failed, return a */
- return (HParmBlkPtr) 0; /* error that thinks its a ptr */
-
- block->fileParam.ioCompletion = NULL; /* no completion routine */
- block->fileParam.ioNamePtr = name; /* full pathname to file... */
- block->fileParam.ioVRefNum = NULL; /* don't need an VRefNum */
- block->fileParam.ioDirID = NULL; /* don't need the dirID */
- block->ioParam.ioPermssn = prm; /* set the access mode */
- block->ioParam.ioMisc = NULL; /* use Volume buffer... */
- block->ioParam.ioBuffer = buffer; /* put buffer in its place */
- err = PBHOpen (block,false); /* synchronusly open file */
-
- if (err) { /* if there was an error */
- DisposPtr (buffer); /* free the buffer space */
- DisposPtr ((Ptr)block); /* free the space for the block */
- return 0; /* return 0 */
- } else
- return block; /* otherwise return the block */
- }
-
- /*
- ** h2pstr (dest,source)
- ** does what it says
- **
- */
- void h2pstr (dest,source)
- char *dest;
- Handle source;
- {
- strcpy ((char *) dest, *source);
- dest = c2pstr (dest);
- }
-
- /*
- ** str2h (str)
- ** copies a string into a handle and returns it
- */
-
- Handle str2h (str)
- char *str;
- {
- Handle new;
-
- new = NewHandle ((long) strlen(str) + 1);
- strcpy ((char *) (*new), str);
-
- return (new);
- }
-